import turtle
import random

# 3.修改递归树
turtle.hideturtle()
turtle.setup(width=1600,height=1200)
t = turtle.Turtle()
turtle.tracer(False)

def tree(l):
    if l>3:
        t.pensize(l//5 if l>=10 else 1)
        pencolor ="#AA5C44" if l>10 else "#41A34C"
        t.pencolor(pencolor)
        t.forward(l)
        r = 0.8-l/120
        ar=20*random.uniform(1-0.8*r,1+0.8*r)
        al=20*random.uniform(1-0.8*r,1+0.8*r)
        if random.random()>0.5:
            t.right(ar)
            tree(l*random.uniform(0.8-0.2*r,0.8+0.2*r))
            t.left(ar+al)
            tree(l*random.uniform(0.8-0.2*r,0.8+0.2*r))
            t.right(al)
        else:
            t.left(al)
            tree(l*random.uniform(0.8-0.2*r,0.8+0.2*r))
            t.right(al+ar)
            tree(l*random.uniform(0.8-0.2*r,0.8+0.2*r))
            t.left(ar)
        t.pencolor(pencolor)
        t.backward(l)

t.left(90)
t.penup()
t.goto((0,-570))
t.pendown()
tree(200)
# turtle.done()
turtle.getscreen().getcanvas().postscript(file="tree.eps")


